<template>
  <div>
      <span @click="btn">点击求和</span>
      <p>{{sum}}</p>
  </div>
</template>

<script>
export default {
  data () {
    return {
      sum: 0,
      arr: [{
        name: '小明',
        age: 18
      }, {
        name: '小花',
        age: 25
      }, {
        name: '小爱',
        age: 21
      }]
    }
  },
  methods: {
    btn () {
      this.arr.forEach(obj => {
        this.sum += obj.age
      })
      return this.sum
    }

  }
}
</script>

<style>
</style>
